<template>
	<view style="display: flex; align-items: center; justify-content: center; flex-direction: column; margin: 40rpx;">
		<image src="https://cdn.weixinchattools.top/logn.png" style="margin: 100rpx; width: 200rpx; height: 200rpx;" mode="widthFix"></image>
		<view class="" style="width: 100%; display: flex;align-items: center; font-weight: 700;">
			<view class="" >
				账号:
			</view>
			<view class="" style="border-bottom: 2rpx solid #e5e5e5; flex: 1; margin-left: 20rpx;">
				<input style="height: 88rpx; line-height: 88rpx;" type="text" placeholder="请输入账号" v-model="data.phone">
			</view>
		</view>
		<view class="" style="width: 100%; display: flex;align-items: center; font-weight: 700;">
			<view class="">
				密码:
			</view>
			<view class="" style="flex: 1; border-bottom: 2rpx solid #e5e5e5; margin-left: 20rpx;">
				<input  style="height: 88rpx; line-height: 88rpx;" type="text" placeholder="请输入密码" v-model="data.password">
			</view>
		</view>
		<view class="" style="width: 100%; margin: 60rpx 0;">
			<button style="background-color: #007aff;" @click="loginAction" type="primary" size="default">确定</button>
		</view>
	</view>
</template>

<script>
	import api from '../../utils/interface.js'
	
	export default {
		data() {
			return {
				data:{}
			}
		},
		onLoad() {
			const login = uni.getStorageSync("login")
			console.log(login);
			if(login == true){
				uni.reLaunch({
				    url: '/pages/index/index' // 同样需要根据自己项目的文件结构进行调整
				});
			}
		},
		methods: {
			async loginAction() {
				console.log();
				const config = {
					url: api.baseUrl + api.login,
					method: 'post',
					data:this.data
				}
				const {
					data,
					code,
					msg
				} = await this.$http.request(config)
				console.log(code, data);
				if (code == 1) {
					uni.setStorageSync('login', true)
					uni.setStorageSync('data', data)
					
					uni.reLaunch({
					    url: '/pages/index/index' // 同样需要根据自己项目的文件结构进行调整
					});
				} else {
					uni.showToast({
						icon: "none",
						title: msg
					})
				}
			},
		}
	}
</script>

<style>

</style>
